package com.kokomi.controller;

import com.kokomi.pojo.VO.OrderVo;
import com.kokomi.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
@Api(tags = "订单模块")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 创建订单
     */
    @PostMapping("/createOrder/{userId}/{addressId}")
    public ResponseEntity createOrder(@PathVariable("userId") long userId, @PathVariable("addressId") long addressId) {

        String orderNum = orderService.createOrder(userId, addressId);
        return ResponseEntity.ok("订单提交成功，订单号：" + orderNum);

    }

    /**
     * 查询订单
     */
    @GetMapping("/loadOrdersByStatus/{userId}/{status}")
    @ApiOperation("查询指定状态的订单")
    public ResponseEntity<List<OrderVo>> loadOrdersByStatus(@PathVariable("userId")Long userId, @PathVariable("status")Integer status) {
        //调用业务层查询订单
        List<OrderVo> orderVos = orderService.queryOrder(userId, status);
        return ResponseEntity.ok(orderVos);
    }
}
